function featuresNorm = NormalizeFeatures(features)
% Normalize image features to have zero mean and unit variance. This
% normalization can cause k-means clustering to perform better.
%
% INPUTS
% features - An array of features for an image. features(i, j, :) is the
%            feature vector for the pixel img(i, j, :) of the original
%            image.
%
% OUTPUTS
% featuresNorm - An array of the same shape as features where each feature
%                has been normalized to have zero mean and unit variance.

    features = double(features);
    featuresNorm = features;
    m=size(featuresNorm,1);
    n=size(featuresNorm,2);
    k=size(featuresNorm,3);
    for i=1:k
        vector=reshape(featuresNorm(:,:,i),1,m*n);
        featuresNorm(:,:,i)=(featuresNorm(:,:,i)-mean(vector))./std(vector);
    end
end